﻿using UnityEngine;
using System.Collections;

public class MainControl : MonoBehaviour {

	// Use this for initialization

	void Awake() {
		Application.targetFrameRate = 60;
		Screen.SetResolution(720,480,true);
	}
	void Start () {
	}
	
	// Update is called once per frame
	void Update () {
		if (JohnnyUIFunctions.IsInTouchState && !JohnnyUIFunctions.IsInSecondFingerTouchState) {
			//Debug.Log("HERE");
			float xCenter = Screen.width / 2f;
			float yCenter = Screen.height / 2f;
			
			float xDistance = JohnnyUIFunctions.FirstFingerCurrentPosition.x - xCenter;
			float yDistance = JohnnyUIFunctions.FirstFingerCurrentPosition.y - yCenter;
			
			Quaternion Bueler = Camera.main.transform.rotation;
			//Vector3 Bueler2 = new Vector3(0f,0f,0f);
			//Bueler2.x = yDistance * 0.25f;
			//Bueler2.y = -1f * xDistance * 0.25f;
			
			
			Quaternion Bueler2 = Quaternion.Euler(yDistance * 0.25f, -xDistance * 0.25f, 0f);
			if (Bueler2.x > 0.5f) Bueler2.x = 0.5f;
			if (Bueler2.y > 0.5f) Bueler2.y = 0.5f;
			if (Bueler2.z > 0.5f) Bueler2.z = 0.5f;
			if (Bueler2.x < -0.5f) Bueler2.x = -0.5f;
			if (Bueler2.y < -0.5f) Bueler2.y = -0.5f;
			if (Bueler2.z < -0.5f) Bueler2.z = -0.5f;
			
			Camera.main.transform.localEulerAngles = Quaternion.Lerp(Bueler,Bueler2,Time.deltaTime * 2f).eulerAngles;
		}
		else if (JohnnyUIFunctions.IsInSecondFingerTouchState) {
			float xDistanceStart = JohnnyUIFunctions.SecondFingerStartPosition.x - JohnnyUIFunctions.FirstFingerStartPosition.x;
			float yDistanceStart = JohnnyUIFunctions.SecondFingerStartPosition.y - JohnnyUIFunctions.FirstFingerStartPosition.y;
			float xDistanceCurrent = JohnnyUIFunctions.SecondFingerCurrentPosition.x - JohnnyUIFunctions.FirstFingerCurrentPosition.x;
			float yDistanceCurrent = JohnnyUIFunctions.SecondFingerCurrentPosition.y - JohnnyUIFunctions.FirstFingerCurrentPosition.y;
			float distanceStart = Mathf.Sqrt(xDistanceStart * xDistanceStart + yDistanceStart * yDistanceStart);
			float distanceCurrent = Mathf.Sqrt(xDistanceCurrent * xDistanceCurrent + yDistanceCurrent * yDistanceCurrent);
			float deltaDistance = (distanceCurrent - distanceStart);

			Camera.main.fieldOfView -= (deltaDistance / 100.0f);
		}

	}
}
